#include <linux/kthread.h>

static struct task_struct *io_task;

static int syncfs_io_thread(void * unused)
{
    while(!kthread_should_stop()){
        set_current_state(TASK_INTERRUPTIBLE);
		schedule();
    }
    return 0;
}

void syncfs_stop_iothread(void)
{
    if(io_task){
	    kthread_stop(io_task);
        io_task = NULL;
    }
}

int syncfs_start_iothread(void)
{
    int err = 0;
    kthread_run(syncfs_io_thread, NULL, "syncfs-io-thread");
    if (IS_ERR(io_task)) {
        err = PTR_ERR(io_task);
        goto error;
    }
    /* others */
    return 0; 
error: 
    return err;
}

